package com.ourteam.frame.web;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.ui.UIConfigFactory;
import net.ui.model.tab.TabbedPaneConfig;
import net.ui.model.table.TableBean;

public class ApplicationModel implements Serializable {

	private boolean fullWidth = false;

	private Map<String, String> appConfigMap = new HashMap<>();

	private String userName;

	private long userId;

	private String userAccount;

	private String unitName;

	private String userPhoto;

	private String[] userRoleNames;
	
	private long[] userRoleIds;

	private long selectedDomainId;

	private AppDomain selectedDoamin;

	private List<AppDomain> appDomains;

	private long selectedModuleId;

	private MenuItem[] menuItems;

	private String userLocaltion;

	private String serverLocaltion;

	private Date loginTime;

	private AppMessage appMessage;

	private String actionHandler;

	public boolean hasErrorAppMessage() {
		return appMessage != null && appMessage.getType().equals("danger");
	}

	public boolean hasAppMessage() {
		return appMessage != null;
	}

	public void setAppMessage(String type, String content) {
		appMessage = new AppMessage(type, content);
	}

	public AppMessage getAppMessage() {
		return appMessage;
	}

	public void setAppErrorMessage(String content) {
		appMessage = new AppMessage("danger", content);
	}

	public void setAppWarningMessage(String content) {
		appMessage = new AppMessage("warning", content);
	}

	public void setAppInfoMessage(String content) {
		appMessage = new AppMessage("info", content);
	}

	public void setAppSuccessMessage(String content) {
		appMessage = new AppMessage("success", content);
	}

	public void clearAppMessage() {
		appMessage = null;
	}

	public boolean isFullWidth() {
		return fullWidth;
	}

	public void setFullWidth(boolean fullWidth) {
		this.fullWidth = fullWidth;
	}

	public AppDomain getSelectedDoamin() {
		return selectedDoamin;
	}

	public void setSelectedDoamin(AppDomain selectedAppDoamin) {
		this.selectedDoamin = selectedAppDoamin;
		this.menuItems = selectedAppDoamin.getMenuItems();
	}

	public long getSelectedDomainId() {
		return selectedDomainId;
	}

	public void setSelectedDomainId(long selectedDomainId) {
		this.selectedDomainId = selectedDomainId;
	}

	public List<AppDomain> getAppDomains() {
		return appDomains;
	}

	public void setAppDomains(List<AppDomain> appDomains) {
		this.appDomains = appDomains;
	}

	public long getSelectedModuleId() {
		return selectedModuleId;
	}

	public void setSelectedModuleId(long selectedModuleId) {
		this.selectedModuleId = selectedModuleId;
	}

	public String getAppVersion() {
		return this.appConfigMap.get("appVersion");
	}

	public String getAppName() {
		return this.appConfigMap.get("appName");
	}

	public String getAppDescription() {
		return this.appConfigMap.get("appDesc");
	}

	public String getAppIcon() {
		return this.appConfigMap.get("appIcon");
	}

	public String getUserAccount() {
		return userAccount;
	}

	public Map<String, String> getAppConfigMap() {
		return appConfigMap;
	}

	public void setUserAccount(String userAccount) {
		this.userAccount = userAccount;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserPhoto() {
		return userPhoto;
	}

	public void setUserPhoto(String userPhoto) {
		this.userPhoto = userPhoto;
	}

	public MenuItem[] getMenuItems() {
		return menuItems;
	}

	public void setMenuItems(MenuItem[] menuItems) {
		this.menuItems = menuItems;
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		this.userId = userId;
	}

	public TabbedPaneConfig getUITabConfig(String tabConfigId) {
		return UIConfigFactory.getInstance(tabConfigId).getTabConfig(tabConfigId);
	}

	public TableBean getUITableConfig(String tableConfigId) {
		return UIConfigFactory.getInstance(tableConfigId).getTableConfig(tableConfigId);
	}

	public String getUserLocaltion() {
		return userLocaltion;
	}

	public void setUserLocaltion(String userLocaltion) {
		this.userLocaltion = userLocaltion;
	}

	public Date getLoginTime() {
		return loginTime;
	}

	public void setLoginTime(Date loginTime) {
		this.loginTime = loginTime;
	}

	public String getServerLocaltion() {
		return serverLocaltion;
	}

	public void setServerLocaltion(String serverLocaltion) {
		this.serverLocaltion = serverLocaltion;
	}

	public String getActionHandler() {
		return actionHandler;
	}

	public void setActionHandler(String actionHandler) {
		this.actionHandler = actionHandler;
	}

	public String[] getUserRoleNames() {
		return userRoleNames;
	}

	public void setUserRoleNames(String[] userRoleNames) {
		this.userRoleNames = userRoleNames;
	}

	public String getUnitName() {
		return unitName;
	}

	public void setUnitName(String unitName) {
		this.unitName = unitName;
	}

	public long[] getUserRoleIds() {
		return userRoleIds;
	}

	public void setUserRoleIds(long[] userRoleIds) {
		this.userRoleIds = userRoleIds;
	}

}
